<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>Cesium地球初始化</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box {
            display: grid;
            grid-template-columns: 1fr 1fr;
            margin-bottom: 10px;
            align-items: center;
            grid-row-gap: 5px;

        }

        .btn {
            display: grid;
            align-items: center;
            grid-template-columns: 1fr;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for="">高度</label><input type="number" id="height" value="300" onchange="setHeight()">
            <label for="">路径样式</label>
            <select name="mode" id="mode1" onchange="setMode()">
                <option value="danger">模式一</option>
                <option value="checkerboard">模式二</option>
                <option value="warning">模式三</option>
                <option value="cord">模式四</option>
                <option value="scanline" selected>模式五</option>
                <option value="honeycomb">模式六</option>
            </select>
            <label for="">面积</label>
            <p id="area"></p>
            <label for="">周长</label>
            <p id="perimeter"></p>
        </div>
        <div class="btn">
            <button onclick="paintESPolygonFence()">重新绘制</button>
            <button onclick="flyTo()">飞行定位</button>

        </div>

    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/
        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']
        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;
        // 监听视口状态
        objm.viewerCreatedEvent.don((viewer) => {
            viewer.flyIn(
                [
                    109.87224744702256,
                    19.476031478186112,
                    878.3591685982825
                ], [
                358.3417142046332,
                -17.623833540284668,
                0.00381778482044597
            ], 3
            )
        });
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer(document.getElementById("app"));
        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 16,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        /** ---------------------------------电子围栏------------------------------------**/
        const sceneObject = objm.createSceneObject('ESPolygonFence')
        // 围栏高度
        sceneObject.height = 300

        // 材质模式
        sceneObject.materialMode = "scanline"

        // 监听面积
        sceneObject.areaChanged.don((val) => {
            document.getElementById('area').innerText = val.toFixed(2) + ' 平方米'
        })

        // 监听周长
        sceneObject.perimeterChanged.don((val) => {
            document.getElementById('perimeter').innerText = val.toFixed(2) + ' 米'
        })
        // 点位
        sceneObject.points = [
            [
                109.87061016305452,
                19.494870951289677,
                0
            ],
            [
                109.87441445496161,
                19.499090402749637,
                0
            ],
            [
                109.87837000313434,
                19.494417233556952,
                0
            ],
            [
                109.87552194783383,
                19.491478516833368,
                0
            ]
        ]

        // 创建电子围栏
        function paintESPolygonFence() {
            sceneObject.editing = false
            sceneObject.points = []
            sceneObject.editing = true
        }

        // 设置围栏高度
        function setHeight() {
            sceneObject.height = Number(document.getElementById('height').value)
        }

        // 设置材质模式
        function setMode() {
            sceneObject.materialMode = document.getElementById('mode1').value
        }

        // 飞行定位
        function flyTo() {
            sceneObject.flyTo()
        }
    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>